<?php 
//引入打印函数
	include "./functions.php";
//设置时区，东八区
	date_default_timezone_set('PRC');
//引入数据库
	$date= include "./date.php";
//判断如果post提交
 if(IS_POST){
// 	$date[]=$_POST;
   	$a=$_POST;
	array_unshift($date,$a);
//	返回合法的php代码
//	如果传递第二个参数，不会直接输出，而是返还给变量
	/*$phpCode = var_export($date,true);
//	把字符串写到文件里
	file_put_contents('./date.php',"<?php return $phpCode ?>");*/
	
	date_to_file($date,'./date.php');
	success('发表成功','./message.php');
 }









 ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
	$(function(){
//		给表情图片添加鼠标单击事件
		var bqb=['<img src="images/01.gif"/>','<img src="images/02.gif"/>','<img src="images/03.gif"/>','<img src="images/04.gif"/>','<img src="images/05.gif"/>','<img src="images/06.gif"/>','<img src="images/07.gif"/>','<img src="images/08.gif"/>','<img src="images/09.gif"/>','<img src="images/10.gif"/>','<img src="images/11.gif"/>','<img src="images/12.gif"/>','<img src="images/13.gif"/>','<img src="images/14.gif"/>','<img src="images/15.gif"/>','<img src="images/16.gif"/>','<img src="images/17.gif"/>','<img src="images/18.gif"/>','<img src="images/19.gif"/>','<img src="images/20.gif"/>','<img src="images/21.gif"/>'];
		$('#mes .box form ul .ly .bqb img').click(function(){
			s=$(this).index();
//			当点击其中一个表情的时候将整个标签插入textarea标签中
			var con=$(this).parents('.ly').find('.liuyan').val();
			$(this).parents('.ly').find('.liuyan').val(con+bqb[s]);
		})
		
//		重置按钮删除所有表单里的value值	
		$('#mes .box form ul .tj .chongzhi').click(function(){
			$(this).parents('ul').find('.bt .biaoti').val('');
			$(this).parents('ul').find('.ly .liuyan').val('');
			$(this).parents('ul').find('.nc .nicheng').val('');
			$(this).parents('ul').find('.tx .photo').val('');
		})
//		给头像选择的label标签添加一个鼠标单击事件
		$('#mes .box form ul .tx .torgether label').click(function(){
		
			$(this).parent('.torgether').css({'border':'2px solid #7B7AB5'}).siblings('.torgether').css({'border':'2px solid #EEE6D1'});
		})
		
		
	})
</script>
<link rel="stylesheet" href="css/mes.css" />
</head>

<body>
	<div id="mes">
		<div class="title">
			<img src="images/title.png" alt="" class="wz1"/>
		</div>
		<div class="message">
			<p class="wz">留言列表</p>
			<div class="bz">
			<?php foreach($date as $k => $v): ?>
				<div class="nr">
					<div class="left">
						<img src="images/tx<?php echo $v['photo'] ?>" alt="" class="tx"/>
						<p class="nc">昵称:<?php echo $v['nickname'] ?></p>
					</div>
					<div class="middle">
						<p class="bt">主题:<?php echo $v['them'] ?></p>
						<p class="ly">内容:<?php echo $v['content'] ?></p>
						<p class="sj"><?php echo $v['time'] ?></p>
						<a href="./edit.php?id=<?php echo $k ?>;" class='xiugai'>修改</a>
						<a href="javascript:del(<?php echo $k ?>);" class='shanchu'>删除</a>
					</div>
				</div>
			<?php endforeach ?>	
			</div>	
		</div>
		<!--jq代码 实现删除的时候，提示是否删除-->
		<script type="text/javascript">
			function del (id){
//				提示确认删除吗，确认就跳转
				if(confirm('您确认删除这条留言？')){
//					确认跳转
					location.href="./del.php?id="+id;
				}
				
			}
		
		</script>	
		
	
		<div class="box">
			<p class="wz">发布留言</p>
			<form action="" method="post">
				<ul>
					<li class="bt" style="height:30px;">
						<p>标题</p>
						<input type="text" name="them"  class="biaoti"/>
					</li>
					<li class="ly" style="height:150px; position:relative;">
						<p style="height:150px; line-height:9em;">留言内容</p>
						<textarea class="liuyan" name="content"></textarea>
						<div class="bqb">
							<img src="images/01.gif" alt="" />
							<img src="images/02.gif" alt="" />
							<img src="images/03.gif" alt="" />
							<img src="images/04.gif" alt="" />
							<img src="images/05.gif" alt="" />
							<img src="images/06.gif" alt="" />
							<img src="images/07.gif" alt="" />
							<img src="images/08.gif" alt="" />
							<img src="images/09.gif" alt="" />
							<img src="images/10.gif" alt="" />
							<img src="images/11.gif" alt="" />
							<img src="images/12.gif" alt="" />
							<img src="images/13.gif" alt="" />
							<img src="images/14.gif" alt="" />
							<img src="images/15.gif" alt="" />
							<img src="images/16.gif" alt="" />
							<img src="images/17.gif" alt="" />
							<img src="images/18.gif" alt="" />
							<img src="images/19.gif" alt="" />
							<img src="images/20.gif" alt="" />
							<img src="images/21.gif" alt="" />
							
						</div>
					</li>
					<li class="nc" style="height:30px;">
						<p style="height:30px;">昵称</p>
						<input type="text" name="nickname"  class="nicheng"/>
					</li>
					<li class="tx" style="height:103px;">
						<p style="height:103px; line-height:7em;">选择头像</p>
						
						<div class="torgether">
							<label for="pic1"><img src="images/tx1.jpg" alt="" class="tp"/></label>
							<input type="radio" name="photo" id="pic1" value="1.jpg" checked="checked" class="photo"/>
						</div>
						<div class="torgether">
							<label for="pic2"><img src="images/tx2.jpg" alt="" class="tp"/></label>
							<input type="radio" name="photo"  id="pic2" value="2.jpg" class="photo"/>
						</div>
						<div class="torgether">
							<label for="pic3"><img src="images/tx3.jpg" alt="" class="tp"/></label>
							<input type="radio" name="photo"  id="pic3" value="3.jpg" class="photo"/>
						</div>
						<div class="torgether">
							<label for="pic4"><img src="images/tx4.jpg" alt="" class="tp"/></label>
							<input type="radio" name="photo"  id="pic4" value="4.jpg" class="photo"/>
						</div>
						<div class="torgether">
							<label for="pic5"><img src="images/tx5.jpg" alt="" class="tp"/></label>
							<input type="radio" name="photo"  id="pic5" value="5.jpg" class="photo"/>
						</div>
						<div class="torgether">
							<label for="pic6"><img src="images/tx6.jpg" alt="" class="tp"/></label>
							<input type="radio" name="photo"  id="pic6" value="6.jpg" class="photo"/>
						</div>
						
					</li>
					<li class="tj" style="position:relative;">	
						<input type="submit" value="提交" class="tijiao"/>
						<input type="button" name="chongzhi" value="重置" class="chongzhi"/>
						<input type="text" name="time" value="<?php echo date("Y-m-d H:i:s"); ?>"  style="display:none;"/>
					</li>
				</ul>
			</form>
		</div>
	</div>
</body>
</html>
